package com.atguigu.mr.index;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @description: xxx
 * @time: 2020-01-06 20:59
 * @author: baojinlong
 **/
public class TwoIndexReducer extends Reducer<Text, Text, Text, Text> {
    private Text nowValue = new Text();

    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        // 拿到当前数据 atguigu-a.txt 3 ==> atguigu c.txt-->3
        StringBuilder stringBuilder = new StringBuilder();
        for (Text value : values) {
            String tmpValue = value.toString();
            stringBuilder.append(tmpValue.replace("\t", "-->")).append("\t");
        }
        nowValue.set(stringBuilder.toString());
        context.write(key, nowValue);
    }
}
